package com.springcloud.gateway.admin.controller;


import com.springcloud.common.core.entity.R;
import com.springcloud.gateway.admin.entity.GatewayRoute;
import com.springcloud.gateway.admin.service.GatewayRouteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author mori
 */
@RestController
@RequestMapping("/gateway/routes")
@Api("gateway routes")
@Slf4j
public class GatewayRouteController {

    private GatewayRouteService gatewayRoutService;

    public GatewayRouteController(GatewayRouteService gatewayRoutService) {
        this.gatewayRoutService = gatewayRoutService;
    }

    @ApiOperation(value = "新增网关路由", notes = "新增一个网关路由")
    // @ApiImplicitParam(name = "gatewayRoute", value = "新增网关路由", required = true, dataType = "GatewayRoute")
    @PostMapping
    public R add(@RequestBody GatewayRoute gatewayRoute) {
        return R.ok(gatewayRoutService.add(gatewayRoute));
    }

    @ApiOperation(value = "删除网关路由", notes = "根据url的id来指定删除对象")
    // @ApiImplicitParam(paramType = "path", name = "id", value = "网关路由ID", required = true, dataType = "long")
    @DeleteMapping(value = "/{id}")
    public R delete(@PathVariable String id) {
        return R.ok(gatewayRoutService.delete(id));
    }

    @ApiOperation(value = "修改网关路由", notes = "修改指定网关路由信息")
 /*   @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "网关路由ID", required = true, dataType = "long"),
            @ApiImplicitParam(name = "gatewayRoute", value = "网关路由实体", required = true, dataType =
                    "GatewayRoute")
    })*/
    @PutMapping(value = "/{id}")
    public R update(@PathVariable String id, @RequestBody GatewayRoute gatewayRoute) {
        return R.ok(gatewayRoutService.update(gatewayRoute));
    }

    @ApiOperation(value = "获取网关路由", notes = "根据id获取指定网关路由信息")
    //@ApiImplicitParam(paramType = "path", name = "id", value = "网关路由ID", required = true, dataType = "long")
    @GetMapping(value = "/{id}")
    public R get(@PathVariable String id) {
        return R.ok(gatewayRoutService.get(id));
    }

    @PostMapping(value = "/overload")
    public R overload() {
        return R.ok(gatewayRoutService.overload());
    }
}
